﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DevExpress.Web.Mvc;

namespace KimPhongCRM.Controllers
{
    public class UserController : Controller
    {
        KimPhongCRM.Models.Entities db = new Models.Entities();
        // SET /Data/
        private void setData()
        {
            ViewData["Role"] = db.Roles.ToList();
        }
        // GET: /User/

        public ActionResult Index()
        {
            setData();
            return View();
        }


        [ValidateInput(false)]
        public ActionResult ListUserPartial()
        {
            setData();
            var model = db.sp_Select_User_All().ToList();
            return PartialView("_ListUserPartial", model);
        }
        
        [HttpPost, ValidateInput(false)]
        public ActionResult ListUserPartialAddNew(KimPhongCRM.Models.sp_Select_User_All_Result item)
        {
            setData();
            var model = new object[0];
            if (ModelState.IsValid)
            {
                try
                {
                    // Insert here a code to insert the new item in your model
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("_ListUserPartial", model);
        }
        
        [HttpPost, ValidateInput(false)]
        public ActionResult ListUserPartialUpdate(KimPhongCRM.Models.sp_Select_User_All_Result item)
        {
            setData();
            var model = new object[0];
            if (ModelState.IsValid)
            {
                try
                {
                    // Insert here a code to update the item in your model
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("_ListUserPartial", model);
        }
    
        [HttpPost, ValidateInput(false)]
        public ActionResult ListUserPartialDelete(System.Guid UserId)
        {
            setData();
            var model = new object[0];
            if (UserId != null)
            {
                try
                {
                    // Insert here a code to delete the item from your model
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            return PartialView("_ListUserPartial", model);
        }
    }
}
